<!---
*****************************************************************************************************
*Author: Jon Wallen                                                                                 *
*www.cfshopkart.com                                                                                 *
*                                                                                                   *
*                                                                                                   *
*Dumps settings to the users folder to keep database load low when browsing a store                 *
*                                                                                                   *
*Version:  1.0                                                                                      *
*License:  Part of CF Shopkart and may only be distributed with it.                                 *
*****************************************************************************************************

Revision History:

-Revised for substores...now dumps override settings at end

--->
<cfcomponent>
	
	<!---****WRITE SETTINGS*****---->
	<cffunction name="writesettings" returntype="string" description="Writes the settings file to the configuration folder">
	<cfargument name = "path" type="string" required="no" default="#request.basepath#" hint="Full path to the installation folder">
	<cfargument name = "cfdsn" type="string" required="no" default="#request.dsn#" hint="Coldfusion dsn of the settings">
    
        <cfquery name = "qsettings" datasource="#cfdsn#">
        SELECT * FROM core_settings
        </cfquery>

		<!---clear file--->
		<cffile action = "write" file="#path#config/settings.cfm" output="" mode="777">

		<!---write main settings--->
        <cfset col_list = qsettings.columnlist>
            
        <cfloop from="1" to = "#listlen(col_list)#" index="c">
            <cfset thiscol = listgetat(col_list, c)>   
			<cfset requestvar = 'REQUEST.#thiscol#'>
            <cfset requestvar = lcase(requestvar)>
            <cfset requestval = 'qsettings.#thiscol#'>
            <cfset requestval = evaluate(requestval)>
        
           <cfif NOT requestval CONTAINS "'">
				<cfset thisline = "<cfset #requestvar# = '#requestval#'>">
            <cfelse>
	            <cfset thisline = '<cfset #requestvar# = "#requestval#">'>
            </cfif>
            
            <cffile action = "append" file="#path#config/settings.cfm" output="#thisline#" addnewline="yes">
        </cfloop>
   
	 <cfreturn outputmsg>

	</cffunction>
</cfcomponent>